package T41_T50;

import datastructure.TreeNode;

public class T42 {
    public TreeNode sortedArrayToBST(int[] nums) {
        return transFormBST(nums,0,nums.length-1);
    }
    private TreeNode transFormBST(int[]nums,int low,int high){
        if (low>high)return null;
        //先找到中间节点作为根节点
        int mid = low + (high - low) / 2;
        TreeNode root=new TreeNode(nums[mid]);
        root.left=transFormBST(nums,low,mid-1);
        root.right=transFormBST(nums,mid+1,high);
        return root;
    }
}
